# coding=utf-8
# @Author:zcx
# @Time:2024/9/12 11:28
import sys
from PySide6.QtWidgets import QApplication,QWidget,QVBoxLayout,QTableWidget,QLineEdit,QTabWidget,QTextEdit,QTableWidgetItem,QLabel,QHBoxLayout

class MyMainWindow(QWidget):
    def __init__(self):
        super().__init__()
        self.setup_ui()

    def setup_ui(self):
        # 创建主布局和子部件
        # vbox = QVBoxLayout(self)

        tab_widgets = QTableWidget(5, 6, self)
        tab_widgets.resize(800, 600)

        h_box = QHBoxLayout()
        add_label = QLabel("修改")
        del_label = QLabel("删除")
        h_box.addWidget(add_label)
        h_box.addWidget(del_label)


        # tab_widgets.horizontalHeaderItem(i)
        tab_widgets.setHorizontalHeaderLabels(["a", "b", "c", "d", "e", "f"])
        for i in range(5):
            for j in range(6):
                if j != 5:
                    item = QTableWidgetItem(f"行{i}列{j}", type=j)
                else:
                    str_ = add_label.text() + "/" + del_label.text()
                    item = QTableWidgetItem(str_, type=j)
                tab_widgets.setItem(i, j, item)
        # 返回当前选中的item项
        # print(table_widgtes.currentColumn())
        # print(table_widgtes.itemFromIndex())
        # 单元格被点击触发的槽函数，返回的是行数
        tab_widgets.cellClicked.connect(self.cell_item)

    def cell_item(self, item):
        print("被点击了", item)


    # def setup_ui(self):
    #     # 创建主布局和子部件
    #     self.layout = QVBoxLayout(self)
    #     self.tab_widget = QTabWidget()
    #
    #     # 创建两个选项卡
    #     tab1 = QWidget()
    #     tab2 = QWidget()
    #
    #     # 在每个选项卡中添加不同的子部件
    #     label_tab1 = QLabel("This is Tab 1")
    #     text_edit_tab2 = QTextEdit()
    #
    #     # 将子部件添加到相应的选项卡
    #     tab1_layout = QVBoxLayout(tab1)
    #     tab1_layout.addWidget(label_tab1)
    #
    #     tab2_layout = QVBoxLayout(tab2)
    #     tab2_layout.addWidget(text_edit_tab2)
    #
    #     # 将选项卡添加到 QTabWidget
    #     self.tab_widget.addTab(tab1, "Tab 1")
    #     self.tab_widget.addTab(tab2, "Tab 2")
    #
    #     # 将 QTabWidget 添加到主布局
    #     self.layout.addWidget(self.tab_widget)


if __name__ == "__main__":
    app = QApplication(sys.argv)
    window = MyMainWindow()
    window.show()
    sys.exit(app.exec())